//
//  HomeRuleViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/12.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "HomeRuleViewController.h"
#import "RuleCollectionViewCell.h"

@interface HomeRuleViewController ()<UICollectionViewDelegate,
    UICollectionViewDataSource>

@property (strong, nonatomic) UICollectionView *listCollectionView;

@end

@implementation HomeRuleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)initPageControl{
    
    [self.view addSubview:self.listCollectionView];
    [self.listCollectionView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(@0);
        make.bottom.equalTo(@-50);
    }];
    
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setBackgroundImage:[UIImage imageNamed:@"CheckSelected"] forState:UIControlStateNormal];
    [self.view addSubview:closeBtn];
    [closeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@30);
        make.centerX.equalTo(self.view.centerX);
        make.bottom.equalTo(@-5);
    }];
    [closeBtn buttonClick:^{
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}

#pragma mark UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 6;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *header=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
        header.backgroundColor = [UIColor clearColor];
       
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.font = [UIFont systemFontOfSize:20];
        titleLabel.textColor = kTitleColor;
        titleLabel.text = @"客房守则";
        [header addSubview:titleLabel];
        [titleLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.height.equalTo(@35);
            make.centerY.equalTo(header.centerY).offset(kStatusBarHeight);
            make.width.equalTo(@100);
        }];
        
        return header;
    }

    return nil;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    RuleCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"RuleCollectionViewCell" forIndexPath:indexPath];
    cell.titleLabel.text = @"接待老人";
   
    return  cell;
}

//设置每个item的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(SCREEN_WIDTH/3, 40);
}

//设置每个item的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
//    return UIEdgeInsetsMake(self.verSpace, 0, 0, 0);
        return UIEdgeInsetsMake(0, 0, 0, 0);
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    
}

#pragma mark getter
- (UICollectionView*)listCollectionView{
    if (_listCollectionView==nil) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing = 0;
        layout.headerReferenceSize =CGSizeMake(SCREEN_WIDTH,100);
        [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
        
        _listCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
        _listCollectionView.delegate = self;
        _listCollectionView.dataSource = self;
        _listCollectionView.backgroundColor = [UIColor clearColor];
        
        [_listCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
        
        [_listCollectionView registerNib:[UINib nibWithNibName:@"RuleCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"RuleCollectionViewCell"];
     
    }
    
    return _listCollectionView;
}


@end
